{% extends "public/base.html" %}

{% block title %}访问错误{% endblock %}

{% block extra_css %}
<style>
.error-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
    padding: 3rem 1rem;
}

.error-icon {
    font-size: 6rem;
    color: #dc3545;
    margin-bottom: 1.5rem;
}

.error-code {
    font-size: 3rem;
    font-weight: bold;
    color: #495057;
    margin-bottom: 1rem;
}

.error-message {
    font-size: 1.2rem;
    color: #6c757d;
    margin-bottom: 2rem;
    line-height: 1.6;
}

.error-actions {
    margin-top: 2rem;
}

.error-actions .btn {
    margin: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    transition: all 0.3s ease;
}

.error-actions .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border: none;
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
    border: none;
}

.error-details {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 1.5rem;
    margin-top: 2rem;
    text-align: left;
}

.error-details h6 {
    color: #495057;
    margin-bottom: 1rem;
}

.error-details ul {
    color: #6c757d;
    margin: 0;
    padding-left: 1.5rem;
}

.error-details li {
    margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
    .error-container {
        padding: 2rem 1rem;
    }
    
    .error-icon {
        font-size: 4rem;
    }
    
    .error-code {
        font-size: 2rem;
    }
    
    .error-message {
        font-size: 1rem;
    }
    
    .error-actions .btn {
        display: block;
        width: 100%;
        margin: 0.5rem 0;
    }
}

.fade-in {
    animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
</style>
{% endblock %}

{% block content %}
<div class="error-container fade-in">
    <div class="error-icon">
        {% if error_code == 404 %}
        <i class="bi bi-exclamation-triangle"></i>
        {% elif error_code == 403 %}
        <i class="bi bi-shield-exclamation"></i>
        {% elif error_code == 500 %}
        <i class="bi bi-gear-wide-connected"></i>
        {% else %}
        <i class="bi bi-x-circle"></i>
        {% endif %}
    </div>
    
    <div class="error-code">{{ error_code or '错误' }}</div>
    
    <div class="error-message">
        {{ error_message or '抱歉，发生了未知错误' }}
    </div>
    
    <div class="error-actions">
        <a href="javascript:history.back()" class="btn btn-secondary">
            <i class="bi bi-arrow-left me-2"></i>
            返回上页
        </a>
        <a href="/" class="btn btn-primary">
            <i class="bi bi-house me-2"></i>
            返回首页
        </a>
    </div>
    
    <div class="error-details">
        <h6>
            <i class="bi bi-info-circle me-2"></i>
            可能的解决方案
        </h6>
        <ul>
            {% if error_code == 404 %}
            <li>检查访问链接是否正确</li>
            <li>确认链接是否已过期或被禁用</li>
            <li>联系发布者确认链接状态</li>
            {% elif error_code == 403 %}
            <li>检查是否有访问权限</li>
            <li>确认账户状态是否正常</li>
            <li>联系管理员获取帮助</li>
            {% elif error_code == 500 %}
            <li>刷新页面重试</li>
            <li>检查网络连接</li>
            <li>稍后再试或联系技术支持</li>
            {% else %}
            <li>刷新页面重试</li>
            <li>检查网络连接</li>
            <li>清除浏览器缓存</li>
            <li>联系技术支持</li>
            {% endif %}
        </ul>
    </div>
    
    <div class="mt-4">
        <small class="text-muted">
            如果问题持续存在，请联系技术支持
        </small>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
// 自动重试功能（仅对500错误）
{% if error_code == 500 %}
let retryCount = 0;
const maxRetries = 3;

function autoRetry() {
    if (retryCount < maxRetries) {
        retryCount++;
        setTimeout(() => {
            window.location.reload();
        }, 5000 * retryCount); // 递增延迟
    }
}

// 5秒后开始第一次重试
setTimeout(autoRetry, 5000);
{% endif %}

// 键盘快捷键
document.addEventListener('keydown', function(event) {
    if (event.key === 'Escape') {
        history.back();
    } else if (event.key === 'Home') {
        window.location.href = '/';
    } else if (event.key === 'F5' || (event.ctrlKey && event.key === 'r')) {
        // 允许F5或Ctrl+R刷新
        return true;
    }
});
</script>
{% endblock %}